package com.yanqu.road.server.cmd.charitable;

import com.yanqu.road.entity.player.ReturnData;
import com.yanqu.road.pb.charitable.CharitableProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.charitable.CharitableModule;
import com.yanqu.road.server.pb.CharitablePb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @Author wpj
 * @Date 2020/8/30
 */
@Cmd(code = GameProtocol.S_CHARITABLE_SKILL_UPGRADE, desc = "升级行善地")
public class CharitableSkillUpgradeCmd extends AbstractCommand {

    int position;
    int skillId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CharitableProto.CharitablePositionUpgradeReq msg = CharitableProto.CharitablePositionUpgradeReq.parseFrom(packet.getBytes());
        position = msg.getPositionId();
        skillId = msg.getSkillId();
        return true;
    }

    ReturnData returnData;

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        returnData = player.getModule(CharitableModule.class).upgradeSkill(position, skillId);
    }

    @Override
    public void sendData(GamePlayer player) {
        int newLevel = Integer.valueOf(returnData.getParams().get(0));
        player.sendPacket(ClientProtocol.U_CHARITABLE_POSITION_UPGRADE, CharitablePb.getCharitablePositionUpgradeRespMsg(returnData.getRet(), newLevel));
    }
}
